//
//  LXLogger.swift
//  LXExtensions
//
//  Created by yoctech on 2021/8/13.
//

import Foundation

@objc public protocol LXLoggerProtocol: NSObjectProtocol {
    @objc func configLogger()
    
    @objc func log(_ obj: Any, level: LXLogger.LogLevel)
}

@objc public class LXLoggerNormal: NSObject, LXLoggerProtocol {
    @objc public var logLevel: LXLogger.LogLevel
    
    @objc public init(logLevel: LXLogger.LogLevel) {
        self.logLevel = logLevel
    }
    @objc public func configLogger() {
        
    }
    
    @objc public func log(_ obj: Any, level: LXLogger.LogLevel) {
        if logLevel == .none || level == .none {
            return
        }
        if logLevel.rawValue <= level.rawValue {
            print(obj)
        }
    }
    
}

@objc public class LXLogger: NSObject {
    @objc public enum LogLevel: Int {
        case verbose, debug, info, warn, error, none
    }
    @objc public static let shared = LXLogger()
    
    @objc public var logger: LXLoggerProtocol = LXLoggerNormal(logLevel: .verbose)
    
}

public func LXLog(_ obj: Any, level: LXLogger.LogLevel = .debug) {
    LXLogger.shared.logger.log(obj, level: level)
}
